package com.idanchuang.count.dao.impl

import com.idanchuang.count.core.domain.AnalyzeCounter
import spock.lang.Specification

import javax.sql.DataSource

/**
 *
 * @author Richard_yyf* @version 1.0 2021/10/12
 */
class CounterAnalyzeDaoImplTest extends Specification {

    def "MultiInsert2MultiTablesAndAutoCreateTableWhenNotExist"() {

        given:
        def counterAnalyzeDao = new CounterAnalyzeDaoImpl(Mock(DataSource.class))
        def expectSql = "insert into simple_count.test_biz111 using simple_count.counter TAGS ('test', 'biz111') values (1634025506000, 2) simple_count.test_biz111 using simple_count.counter TAGS ('test', 'biz111') values (1634025506000, 2) simple_count.test_biz111 using simple_count.counter TAGS ('test', 'biz111') values (1634025506000, 2)"

        def records = [
                new AnalyzeCounter(ts: 1634025506000, increment: 2, bizNo: "biz111", bizCode: "test"),
                new AnalyzeCounter(ts: 1634025506000, increment: 2, bizNo: "biz111", bizCode: "test"),
                new AnalyzeCounter(ts: 1634025506000, increment: 2, bizNo: "biz111", bizCode: "test")
        ]

        when:
        def retSql = counterAnalyzeDao.buildSqlForInsert2TablesAndAutoCreateTableWhenNotExist(records).trim()

        then:
        retSql == expectSql
    }
}
